package com.lottery.material.service.admin.system.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lottery.material.dao.system.MenuMapper;
import com.lottery.material.pojo.page.PageData;
import com.lottery.material.pojo.system.Menu;
import com.lottery.material.service.admin.system.MenuService;

/**
 * @description 菜单服务接口
 * @author rambo
 * @date 2018年6月7日 下午5:33:50
 */
@Service
public class MenuServiceImpl implements MenuService {

	@Autowired
	private MenuMapper menuMapper;

	/**
	 * @description 通过ID获取其子一级菜单
	 * @param parentId
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Menu> listSubMenuByParentId(String parentId) throws Exception {
		return menuMapper.listSubMenuByParentId(parentId);
	}
	
	/**
	 * @description 通过ID获取其子一级菜单(隐藏菜单不显示)
	 * @param parentId
	 * @return
	 * @throws Exception
	 */
	public List<Menu> listSubMenuByParentId2(String parentId) throws Exception {
		return menuMapper.listSubMenuByParentId2(parentId);
	}

	/**
	 * @description 通过菜单ID获取数据
	 * @param pd
	 * @return
	 * @throws Exception
	 */
	@Override
	public PageData getMenuById(PageData pd) throws Exception {
		return menuMapper.getMenuById(pd);
	}

	/**
	 * @description 新增菜单
	 * @param menu
	 * @throws Exception
	 */
	@Override
	public void saveMenu(Menu menu) throws Exception {
		menuMapper.insertMenu(menu);
	}

	/**
	 * @description 取最大ID
	 * @param pd
	 * @return
	 * @throws Exception
	 */
	@Override
	public PageData findMaxId(PageData pd) throws Exception {
		return menuMapper.findMaxId(pd);
	}

	/**
	 * @description 删除菜单
	 * @param MENU_ID
	 * @throws Exception
	 */
	@Override
	public void deleteMenuById(String MENU_ID) throws Exception {
		menuMapper.deleteMenuById(MENU_ID);
	}

	/**
	 * @description 编辑
	 * @param menu
	 * @return
	 * @throws Exception
	 */
	@Override
	public void edit(Menu menu) throws Exception {
		menuMapper.updateMenu(menu);
	}

	/**
	 * @description 保存菜单图标 
	 * @param pd
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer editicon(PageData pd) throws Exception {
		return menuMapper.editicon(pd);
	}

	/**
	 * @description 获取所有菜单并填充每个菜单的子菜单列表(菜单管理)(递归处理)
	 * @param MENU_ID
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Menu> listAllMenu(String MENU_ID) throws Exception {
		List<Menu> menuList = this.listSubMenuByParentId(MENU_ID);
		for (Menu menu : menuList) {
			menu.setMENU_URL("menu/toEdit.do?MENU_ID=" + menu.getMENU_ID());
			menu.setSubMenu(this.listAllMenu(String.valueOf(menu.getMENU_ID())));
			menu.setTarget("treeFrame");
		}
		return menuList;
	}

	/**
	 * @description 获取所有菜单并填充每个菜单的子菜单列表(系统菜单列表)(递归处理)
	 * @param MENU_ID
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Menu> listAllMenuQx(String MENU_ID) throws Exception {
		List<Menu> menuList = this.listSubMenuByParentId2(MENU_ID);
		for (Menu menu : menuList) {
			menu.setSubMenu(this.listAllMenuQx(String.valueOf(menu.getMENU_ID())));
			menu.setTarget("treeFrame");
		}
		return menuList;
	}

}
